package com.email.logic;

import java.util.Map;

import com.email.base.EmailAction;
import com.email.bean.Operator;
import com.email.bussiness.IOperatorDao;
import com.email.bussiness.OperatorDao;
import com.jgeppert.struts2.jquery.tree.result.TreeNode;
import com.opensymphony.xwork2.ActionContext;

public class Login extends EmailAction {
	private static final long serialVersionUID = 1L;
	private Operator operator;
	private String username;
	private String password;
	private String privilege;	
    private TreeNode node = new TreeNode();
	
	public String execute() throws Exception {
		IOperatorDao operatorDao = new OperatorDao();
		operator = operatorDao.findOperator(this.getUsername(), this.getPassword());
		if(operator == null){
            this.addActionError(getText("Login.errorMSG"));
			return INPUT;
		}
		node = operatorDao.getNode(this.getUsername());//获取自定义的文件夹信息
		Map<String, Object> map = ActionContext.getContext().getSession();
		map.put("OPERATOR", operator);
		ActionContext.getContext().setSession(map);
		return SUCCESS;
	}
	
	public String out() throws Exception {
		Map<String, Object> map = ActionContext.getContext().getSession();
		map.remove("OPERATOR");
		return INPUT;
	}
	
	public String input() throws Exception {
		return INPUT;
	}

	public String getPrivilege() {
		return privilege;
	}

	public void setPrivilege(String privilege) {
		this.privilege = privilege;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public TreeNode getNode() {
		return node;
	}

	public void setNode(TreeNode node) {
		this.node = node;
	}
}
